{include file="public/page_header" /} <!--头部公共区域-->

<div class="layui-layout layui-layout-admin">
  <div class="layui-row">

  </div>
  <div class="table-responsive">
    <table id="table" lay-data="{id: 'idTest'}" lay-filter="test"></table>
  </div>
</div>

{include file="public/page_footer" /} <!--尾部公共区域-->

<script type="text/html" id="barDemo">

</script>
<script type="text/javascript">
  var reload;
  layui.use('table',function(){
    var table = layui.table;
    var tableIns = table.render({
      elem: '#table'
      //,height: 600
      ,url: "{:url('admin/adminlog')}" //数据接口
      ,page: false //开启分页
      ,id: 'idTest'
      ,cols: [[ //表头
        {type:'numbers', title: '序号', width:60}
        ,{field: 'admin_name', title: '用户名',align:'center'}
        ,{field: 'type', title: '名称',align:'center'}
        ,{field: 'content', title: '相关内容',align:'center'}
        ,{field: 'ip', title: '登录IP',align:'center'}
        ,{field: 'create_time', title: '相关时间',align:'center'}
      ]]
    });

    //搜索
    $('#searchBtn').click(function(){
      reload();
    });

    //重载
    reload = function (){
      tableIns.reload({
        where: {
          select:$('#type').val()
        }
        ,page: {
          curr: 1 //重新从第 1 页开始
        }
      });
    }

    //监听工具条
    table.on('tool(test)', function(obj){
      var data = obj.data;
      if(obj.event === 'admin_edit'){
        addAdmin(data.id);
      }
      if(obj.event === 'admin_del'){
        if(data.id === 1){
          layer.msg('超级管理员禁止删除!')
          return false;
        }
        layer.confirm('确定要删除吗？',{
          btn:['确定','取消']
          ,btn2:function (index) {
            layer.close(index)
          }
        },function (index) {
          $.ajax({
            type : "POST",  //提交方式
            url : "{:url('admin/logdel')}",//路径
            data : {
              "id" : data.id,
            },
            success: function(data){
              if(data.code === 0){
                layer.msg('操作成功！')
                reload();
              }else{
                layer.msg('操作失败！')
              }
            }
          })
        })
      }
    });
  });

  $('select').change(function () {
    reload();
  })

</script>

